import csv
import sqlite3

connection = sqlite3.connect('../db.sqlite3')
cursor = connection.cursor()

create_table = '''
create table data_GPU
(
    Name text not null,
    ID text not null,
    PID text not null,
    Platform text not null,
    Price text,
    Performance text,
    Architecture text,
    GRAMType text,
    GRAMCapacity text,
    Power text,
    PCIESlot text,
    GPUF text,
    GPUBW text,
    POut text,
    VOut text,
    Frequency text,
    Process text,
    constraint gpu_pk
        primary key (Name,ID,PID,Platform)
);


'''

cursor.execute(create_table)
file = open('../GetInfo/Details/GPUInfo.csv', encoding='utf-8')
contents = csv.reader(file)
insert_records = "INSERT INTO data_GPU (Name,ID,PID,Platform,Price,Performance,Architecture,GRAMType,GRAMCapacity,Power,PCIESlot,GPUF,GPUBW,POut,VOut,Frequency,Process) " \
                 "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

cursor.executemany(insert_records, contents)
select_all = "SELECT * FROM data_GPU"
rows = cursor.execute(select_all).fetchall()
for r in rows:
    print(r)

# Committing the changes
connection.commit()
connection.close()
